<?php
class PchartsController extends AppController {
     public  $name = 'Pcharts';
     //1   
     public  $uses = null;                                                         
      
     public function grafico0(){
        App::import('Vendor', 'PdataClass', array('file' => 'pchart' . DS . 'pData.class.php'));
        App::import('Vendor', 'PdrawClass', array('file' => 'pchart' . DS . 'pDraw.class.php'));
        App::import('Vendor', 'PimageClass', array('file' => 'pchart' . DS . 'pImage.class.php'));
        $this->autoRender = false;

         /* Create your dataset object */ 
         $myData = new pData(); 
         /* Add data in your dataset */ 
         $myData->addPoints(array(1,3,4,3,5));
         /* Create a pChart object and associate your dataset */ 
         $myPicture = new pImage(700,230,$myData);
         /* Choose a nice font */
        $font_name = $fontFolder = APP.'Vendor'.DS.'pchart'.DS.'fonts';
         $myPicture->setFontProperties(array("FontName"=> $font_name.DS."Forgotte.ttf","FontSize"=>11));
         /* Define the boundaries of the graph area */
         $myPicture->setGraphArea(60,40,670,190);
         /* Draw the scale, keep everything automatic */ 
         $myPicture->drawScale();
         /* Draw the scale, keep everything automatic */ 
         $myPicture->drawSplineChart();
         /* Render the picture (choose the best way) */
         $myPicture->autoOutput(APP.'Vendor'.DS.'pchart'.DS.'pictures'.DS.'grafico0.jpeg');        
         exit;
     }
     public function grafico1(){      
        App::import('Vendor', 'PdataClass', array('file' => 'pchart' . DS . 'pData.class.php'));
        App::import('Vendor', 'PdrawClass', array('file' => 'pchart' . DS . 'pDraw.class.php'));
        App::import('Vendor', 'PimageClass', array('file' => 'pchart' . DS . 'pImage.class.php'));
        $this->autoRender = false;
        /* Objeto con los datos */
        $MyData = new pData();  
        $MyData->addPoints(array(10000,2500,5800,8000,12000,7000),"Curva1");
        $MyData->addPoints(array(4000,7000,8000,5000,9000,8000),"Curva2");
        $MyData->setSerieWeight("Curva1",2);
        $MyData->setSerieTicks("Curva2",4);
        $MyData->setSerieDescription("Curva1","Rango 1");
        $MyData->setSerieDescription("Curva2","Rango 2");
        $MyData->setAxisName(0,"Importe facturado");
        $MyData->addPoints(array("Enero","Febrero","Marzo","Abril","Mayo","Junio"),"Fecha");
        $MyData->setAbscissa("Fecha");
        $MyData->setAbscissaName("Periodo");
        
        // la variable de sesion se usará para parametrizar el gráfico
        //$titulo = $this->Session->read('titulo');
                
        // Create the pChart object 
        $myPicture = new pImage(800,300,$MyData);
        // Turn off AntiAliasing 
        $myPicture->Antialias = FALSE;

        // Borde del grafico
        $myPicture->drawRectangle(0,0,799,299,array("R"=>0,"G"=>0,"B"=>0));

        // Fuente del gráfico
        $font_name = $fontFolder = APP.'Vendor'.DS.'pchart'.DS.'fonts';
        $myPicture->setFontProperties(array("FontName"=>$font_name.DS.'pf_arma_five.ttf',"FontSize"=>6));

        // Defino el area del grafico
        $myPicture->setGraphArea(60,30,750,250);

        // Dibuja escala del grafico
        /* Draw the scale */
        $scaleSettings = array("XMargin"=>10,"YMargin"=>10,"Floating"=>TRUE,"GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE);
        $myPicture->drawScale($scaleSettings);
      
        // Turn on AntiAliasing 
        $myPicture->Antialias = TRUE;
        
        // Dibujo el grafico
        $myPicture->drawLineChart();
        $myPicture->drawPlotChart(array("DisplayValues"=>TRUE,"PlotBorder"=>TRUE,"BorderSize"=>2,"Surrounding"=>-60,"BorderAlpha"=>80));
        
        // Leyendas del grafico
        $myPicture->drawLegend(600,10,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));

        // genero la imagen que muestra la pagina
        $myPicture->autoOutput(APP.'Vendor'.DS.'pchart'.DS.'pictures'.DS.'grafico1.jpeg');        
        exit;
     } 

     public function grafico2(){      
        App::import('Vendor', 'PdataClass', array('file' => 'pchart' . DS . 'pData.class.php'));
        App::import('Vendor', 'PdrawClass', array('file' => 'pchart' . DS . 'pDraw.class.php'));
        App::import('Vendor', 'PimageClass', array('file' => 'pchart' . DS . 'pImage.class.php'));
        $this->autoRender = false;
        /* Objeto con los datos */
        $MyData = new pData();  
        $MyData->addPoints(array(10000,2500,5800,8000,12000,7000),"Curva1");
        $MyData->setSerieWeight("Curva1",0);
        $MyData->setAxisName(0,"Importe facturado");
        $MyData->addPoints(array("01/01","02/01","03/01","04/01","05/01","06/01","07/01","08/01","09/01","10/01",
                                "01/01","02/01","03/01","04/01","05/01","06/01","07/01","08/01","09/01","10/01",
                                "01/01","02/01","03/01","04/01","05/01","06/01","07/01","08/01","09/01","10/01"),"Fecha");
        $MyData->setAbscissa("Fecha");
        $MyData->setAbscissaName("Periodo");
        
        // la variable de sesion se usará para parametrizar el gráfico
        //$titulo = $this->Session->read('titulo');
                
        // Create the pChart object 
        $myPicture = new pImage(1000,400,$MyData);
        // Turn off AntiAliasing 
        $myPicture->Antialias = FALSE;

        // Borde del grafico
        $myPicture->drawRectangle(0,0,999,399,array("R"=>0,"G"=>0,"B"=>0));

        // Titulo del grafico
        $font_folder = APP.'Vendor'.DS.'pchart'.DS.'fonts';
        $myPicture->setFontProperties(array("FontName"=>$font_folder.DS."Forgotte.ttf","FontSize"=>16,"R"=>0,"G"=>0,"B"=>0));
        $myPicture->drawText(450,25,"Facturación desde Fecha1 a Fecha2",array("FontSize"=>16,"Align"=>TEXT_ALIGN_BOTTOMLEFT));
        
        // Fuente del gráfico
        $myPicture->setFontProperties(array("FontName"=>$font_folder.DS.'pf_arma_five.ttf',"FontSize"=>7));

        // Defino el area del grafico
        $myPicture->setGraphArea(50,30,980,350);

        // Dibuja escala del grafico
        /* Draw the scale */
        $scaleSettings = array("XMargin"=>10,"YMargin"=>10,"Floating"=>TRUE,"GridR"=>220,"GridG"=>220,"GridB"=>220,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE);
        $myPicture->drawScale($scaleSettings);
      
        // Turn on AntiAliasing 
        $myPicture->Antialias = TRUE;
        
        // Dibujo el grafico
        $myPicture->drawLineChart();
        $myPicture->drawPlotChart(array("DisplayValues"=>TRUE,"PlotBorder"=>TRUE,"BorderSize"=>2,"Surrounding"=>-60,"BorderAlpha"=>80));
        
        // Leyendas del grafico
//        $myPicture->drawLegend(600,10,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));

        // genero la imagen que muestra la pagina
        $myPicture->autoOutput(APP.'Vendor'.DS.'pchart'.DS.'pictures'.DS.'grafico2.jpeg');        
        exit;
     } 
          
     public function grafico3() {
        App::import('Vendor', 'PdataClass', array('file' => 'pchart' . DS . 'pData.class.php'));
        App::import('Vendor', 'PdrawClass', array('file' => 'pchart' . DS . 'pDraw.class.php'));
        App::import('Vendor', 'PimageClass', array('file' => 'pchart' . DS . 'pImage.class.php'));
        $this->autoRender = false;

        $font_folder = APP.'Vendor'.DS.'pchart'.DS.'fonts';
        
        /* Create and populate the pData object */
        $MyData = new pData();  
        $MyData->addPoints(array(150,220,300,-250,-420,-200,300,200,100),"Server A");
        $MyData->addPoints(array(140,0,340,-300,-320,-300,200,100,50),"Server B");
        $MyData->setAxisName(0,"Hits");
        $MyData->addPoints(array("January","February","March","April","May","Juin","July","August","September"),"Months");
        $MyData->setSerieDescription("Months","Month");
        $MyData->setAbscissa("Months");
        
        /* Create the pChart object */
        $myPicture = new pImage(700,230,$MyData);

        /* Turn of Antialiasing */
        $myPicture->Antialias = FALSE;

        /* Add a border to the picture */
        $myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0));

        /* Set the default font */
        $myPicture->setFontProperties(array("FontName"=>$font_folder.DS."pf_arma_five.ttf","FontSize"=>6));

        /* Define the chart area */
        $myPicture->setGraphArea(60,40,650,200);

        /* Draw the scale */
        $scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE);
        $myPicture->drawScale($scaleSettings);

        /* Write the chart legend */
        $myPicture->drawLegend(580,12,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));

        /* Turn on shadow computing */ 
        $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));

        /* Draw the chart */
        $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
        $settings = array("Gradient"=>TRUE,"GradientMode"=>GRADIENT_EFFECT_CAN,"DisplayPos"=>LABEL_POS_INSIDE,"DisplayValues"=>TRUE,"DisplayR"=>255,"DisplayG"=>255,"DisplayB"=>255,"DisplayShadow"=>TRUE,"Surrounding"=>10);
        $myPicture->drawBarChart();

        /* Render the picture (choose the best way) */
        $myPicture->autoOutput(APP.'Vendor'.DS.'pchart'.DS.'pictures'.DS.'grafico3.jpeg');        
        exit;
    }

     
 }
?>
